home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / iconp.zip / DEAL.ICN < prev    next >
Text File  |  1987-05-29  |  2KB  |  92 lines

  1. #    DEAL(6)
  2. #
  3. #    Shuffle and deal bridge hands
  4. #
  5. #    Ralph E. Griswold
  6. #
  7. #    Last modified 7/10/83
  8. #
  9.  
  10. global deckimage
  11.  
  12. procedure main(x)
  13.    local deck, handsize, Table, hands, bar, i, s
  14.    deck := deckimage := &lcase || &ucase
  15.    bar := repl("-",33)
  16.    handsize := *deck / 4
  17.    hands := 1
  18.    i := 0
  19.    while i < *x do {
  20.       s := x[i +:= 1] | break
  21.       case s of {
  22.          "-h":   hands := integer(x[i +:= 1]) |
  23.             stop("usage:  deal [-h n] [-s n]")
  24.          "-s":   &random := integer(x[i +:= 1]) |
  25.             stop("usage:  deal [-h n] [-s n]")
  26.          default:   stop("usage:  deal [-h n] [-s n]")
  27.          }
  28.       }
  29.    write(bar,"\n")
  30.    every 1 to hands do {
  31.       deck := shuffle(deck)
  32.       Table := [
  33.          show(deck[1+:handsize]),
  34.          show(deck[handsize + 1+:handsize]),
  35.          show(deck[2 * handsize + 1+:handsize]),
  36.          show(deck[3 * handsize + 1+:handsize])
  37.          ]
  38.       every write(repl(" ",10),!Table[1])
  39.       write()
  40.       every i := 1 to 4 do
  41.          write(left(Table[4][i],20),Table[2][i])
  42.       write()
  43.       every write(repl(" ",10),!Table[3])
  44.       write("\n",bar,"\n")
  45.       }
  46. end
  47.  
  48. #  shuffle deck
  49. #
  50. procedure shuffle(deck)
  51.    local m
  52.    every m := *deck to 2 by -1 do
  53.       deck[?m] :=: deck[m]
  54.    return deck
  55. end
  56.  
  57. #  display the hands
  58. #
  59. procedure show(hand)
  60.    static clubs, diamonds, hearts, spades, denom, blanker, suitsize
  61.    initial {
  62.       suitsize := *deckimage / 4
  63.       blanker := repl(" ",suitsize)
  64.       denom := &lcase[1+:suitsize]
  65.       clubs := denom || repl(blanker,3)
  66.       diamonds := blanker || denom || repl(blanker,2)
  67.       hearts := repl(blanker,2) || denom || blanker
  68.       spades := repl(blanker,3) || denom
  69.       }
  70.                 # if a hand consists of all 13 cards of one
  71.                 # suit, that suit will be misformatted slightly
  72.    return [
  73.       "S:" || arrange(hand,spades),
  74.       "H:" || arrange(hand,hearts),
  75.       "D:" || arrange(hand,diamonds),
  76.       "C:" || arrange(hand,clubs)
  77.       ]
  78.    write("\n")
  79. end
  80.  
  81. #  arrange hands for presentation
  82. #
  83. procedure arrange(hand,suit)
  84.    static denom, rank, suitsize
  85.    initial {
  86.       suitsize := *deckimage / 4
  87.       denom := &lcase[1+:suitsize]
  88.       rank := "AKQJT98765432"
  89.       }
  90.    return trim(map(cset(map(hand,deckimage,suit)),denom,rank))
  91. end
  92.